package com.cqjtu.service.serviceImpl;

import com.cqjtu.mapper.TeamsMapper;
import com.cqjtu.mapper.WorkerMapper;
import com.cqjtu.pojo.PageBean;
import com.cqjtu.pojo.Teams;
import com.cqjtu.pojo.Worker;
import com.cqjtu.service.TeamsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeamsServiceImpl implements TeamsService {

    @Autowired
    private WorkerMapper workerMapper;
    @Autowired
    private TeamsMapper teamsMapper;

    //新建班组
    @Override
    public void add(Teams teams) {
        teamsMapper.add(teams);
    }

    //删除班组
    @Override
    public void delete(List<Integer> teamsId) {
        teamsMapper.delete(teamsId);
    }


    //班组id查询
    @Override
    public Teams getById(Integer teamsId) {
        return teamsMapper.getById(teamsId);
    }

    //更新班组
    @Override
    public void update(Teams teams) {
        teamsMapper.update(teams);
    }



    //班组人数增加
    @Override
    public void add2(Worker worker) {
        teamsMapper.add2(worker);
    }



    //班组条件查询（通过班组名称，承包人，班组人数查询）
    @Override
    public PageBean page(Integer page, Integer pageSize, String teamsName, String contractor, Integer teamsNumber, Integer n) {
        //设置分页参数
        PageHelper.startPage(page,pageSize);

        //执行查询
        List<Teams> teamsList = teamsMapper.list(teamsName,contractor,teamsNumber,n);
        Page<Teams> p = (Page<Teams>) teamsList;

        //封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }




}
